home *** CD-ROM | disk | FTP | other *** search
/ Clickx 75 / Clickx 75.iso / software / expressionweb / expressionwebv3 / ExpressionWeb_en.exe / Setup / WeNoLoc.cab / xweb.FPCLASS.DBRegion.ascx < prev    next >
Encoding:
Text File  |  2009-06-09  |  11.5 KB  |  392 lines

  1. <%BeginASP%>@ Control Src="fpdbnet.cs" Language="c#" Inherits="Microsoft.Office.FrontPage.DBInterface.DBRegionBase" <%EndASP%>
  2. <%BeginASP%>@ Import Namespace="System.Collections" <%EndASP%>
  3. <%BeginASP%>@ Import Namespace="System.Data" <%EndASP%>
  4. <%BeginASP%>@ Import Namespace="System.Globalization" <%EndASP%>
  5. <%BeginASP%>@ Register TagPrefix="FPDB" TagName="DBQuery" Src="DBQuery.ascx" <%EndASP%>
  6. <SCRIPT Language="C#" Runat="server">
  7.         Microsoft.Office.FrontPage.DBInterface.DBConnection _connection;
  8.         private DataGrid targetGrid;
  9.         private DBQuery userFieldsControl;
  10.         private Label noResultsLabel;
  11.  
  12.         private bool bPage;
  13.         private int nPageSize;
  14.         private string _customSql;
  15.         private string _dBName;
  16.         private string _maxRecords;
  17.         private string _noResults;
  18.         private string _orderBy;
  19.         private string _pageSize;
  20.         private string _rootPath;
  21.         private string _tableKey;
  22.         private string _tableName;
  23.         private string _target;
  24.         private string _usePaging;
  25.         private string _userFields;
  26.         private string _where;
  27.  
  28.  
  29.  
  30.         public string AllowPaging
  31.         {
  32.             get
  33.             {
  34.                 return _usePaging;
  35.             }
  36.             set
  37.             {
  38.                 _usePaging = value;
  39.             }
  40.         }
  41.  
  42.         public string CustomSql
  43.         {
  44.             get
  45.             {
  46.                 return _customSql;
  47.             }
  48.             set
  49.             {
  50.                 _customSql = value;
  51.             }
  52.         }
  53.     
  54.         public string DBName
  55.         {
  56.             get
  57.             {
  58.                 if(_dBName == null)
  59.                     _dBName = System.Configuration.ConfigurationManager.AppSettings["DBName"];
  60.                 return _dBName;
  61.             }
  62.             set
  63.             {
  64.                 _dBName = value;
  65.             }
  66.         }
  67.  
  68.         public string MaxRecords
  69.         {
  70.             get
  71.             {
  72.                 return _maxRecords;
  73.             }
  74.             set
  75.             {
  76.                 _maxRecords = value;
  77.             }
  78.  
  79.  
  80.         }
  81.  
  82.         public string NoResults
  83.         {
  84.             get
  85.             {
  86.                 return _noResults;
  87.             }
  88.             set
  89.             {
  90.                 _noResults = value;
  91.             }
  92.         }
  93.     
  94.         public string OrderBy
  95.         {
  96.             get
  97.             {
  98.                 return _orderBy;
  99.             }
  100.             set
  101.             {
  102.                 _orderBy = value;
  103.             }
  104.         }
  105.         
  106.         public string PageSize
  107.         {
  108.             get
  109.             {
  110.                 return _pageSize;
  111.             }
  112.             set
  113.             {
  114.                 _pageSize = value;
  115.             }
  116.         }
  117.  
  118.         public string RootPath
  119.         {
  120.             get
  121.             {
  122.                 if(_rootPath == null)
  123.                     _rootPath = ConfigurationManager.AppSettings["RootPath"];
  124.                 return _rootPath;
  125.             }
  126.             set
  127.             {
  128.                 _rootPath = value;
  129.             }
  130.         }
  131.  
  132.         
  133.         
  134.         public string TableKey
  135.         {
  136.             get
  137.             {
  138.                 if(_tableKey == null)
  139.                     _tableKey = ConfigurationManager.AppSettings["TableKey"];
  140.                 return _tableKey;
  141.             }
  142.             set
  143.             {
  144.                 _tableKey = value;
  145.             }
  146.         }
  147.  
  148.         public string TableName
  149.         {
  150.             get
  151.             {
  152.                 if(_tableName == null )
  153.                     _tableName = System.Configuration.ConfigurationManager.AppSettings["TableName"];
  154.                 if(_tableName == null || _tableName.Length == 0)
  155.                     _tableName = "Table";
  156.                 return _tableName;
  157.             }
  158.             set
  159.             {
  160.                 _tableName = value;
  161.             }
  162.         }
  163.         
  164.         public string Target
  165.         {
  166.             get
  167.             {
  168.                 return _target;
  169.             }
  170.             set
  171.             {
  172.                 _target = value;
  173.             }
  174.         }
  175.         
  176.         public string UserFields
  177.         {
  178.             get
  179.             {
  180.                 return _userFields;
  181.             }
  182.             set
  183.             {
  184.                 _userFields = value;
  185.             }
  186.         }
  187.         public string Where
  188.         {
  189.             get
  190.             {
  191.                 return _where;
  192.             }
  193.             set
  194.             {
  195.                 _where = value;
  196.             }
  197.         }
  198.             
  199.         public override void SetConnection( Microsoft.Office.FrontPage.DBInterface.DBConnection connection )
  200.         {
  201.             _connection = connection;
  202.             ApplyConfigSettings();
  203.         }
  204.     
  205.         protected override void OnInit( EventArgs e )
  206.         {
  207.             if(_connection == null)
  208.             {
  209.                 _connection = new Microsoft.Office.FrontPage.DBInterface.DBConnection(Page);
  210.             }
  211.             if(Target != null)
  212.             {
  213.                 System.Web.UI.Control theTargetCandidate = Page.FindControl(Target);
  214.                 if(theTargetCandidate is DataGrid)
  215.                 {
  216.                     targetGrid = (DataGrid)theTargetCandidate;
  217.                 }
  218.             }
  219.             if(NoResults != null)
  220.             {
  221.                 System.Web.UI.Control NoResultsCandidate = Page.FindControl(NoResults);
  222.                 if(NoResultsCandidate is Label)
  223.                 {
  224.                     noResultsLabel = (Label)NoResultsCandidate;
  225.                 }
  226.             }
  227.             if(UserFields != null)
  228.             {
  229.                 System.Web.UI.Control UserFieldsCandidate = Page.FindControl(UserFields);
  230.                 if(UserFieldsCandidate is DBQuery)
  231.                 {
  232.                     userFieldsControl = (DBQuery)UserFieldsCandidate;
  233.                 }
  234.             }
  235.         
  236.             if( AllowPaging != null )
  237.                 bPage = AllowPaging.ToLower(CultureInfo.InvariantCulture).Equals("true");
  238.             
  239.             try{
  240.                 if( PageSize != null )
  241.                 {
  242.                     nPageSize = Convert.ToInt32( PageSize, CultureInfo.InvariantCulture.NumberFormat );
  243.                 }
  244.                 else
  245.                 {
  246.                     nPageSize = 5;
  247.                 }
  248.             }
  249.             catch( Exception ){
  250.                 bPage = false;
  251.             }
  252.             ApplyConfigSettings();
  253.         
  254.             if( bPage )
  255.             {
  256.                 pagerPanel.Visible = true;
  257.                 targetGrid.AllowPaging = true;
  258.                 targetGrid.PagerStyle.Visible = false;
  259.                 targetGrid.PageSize = nPageSize;
  260.                 if ( Session["DataRowAdded"] != null && Session["DataRowAdded"].Equals("true"))
  261.                 {
  262.                     UpdatePager(true);
  263.                     Session["DataRowAdded"] = null;
  264.                 }
  265.                 else
  266.                 {
  267.                     UpdatePager(false);
  268.                 }
  269.             
  270.             }
  271.         }
  272.  
  273.         protected override void OnPreRender( EventArgs e )
  274.         {
  275.             if(!Page.IsPostBack || ( userFieldsControl != null && userFieldsControl.Submitted ))
  276.             {
  277.                 DataBind();
  278.             }
  279.         
  280.             UpdatePager(false);
  281.         }
  282.     
  283.         public override void DataBind()
  284.         {
  285.             if(targetGrid == null)
  286.             {
  287.                 return;
  288.             }
  289.         
  290.             UpdatePager(false);
  291.             DataView theDataView = GetDataView();
  292.             if(noResultsLabel != null)
  293.             {
  294.                 if(theDataView.Count == 0)
  295.                     noResultsLabel.Visible = true;
  296.                 else
  297.                     noResultsLabel.Visible = false;
  298.             }
  299.  
  300.         
  301.             targetGrid.DataSource = theDataView;
  302.         
  303.             targetGrid.DataBind();
  304.         }
  305.     
  306.         private void ApplyConfigSettings()
  307.         {
  308.             _connection.DBName = DBName;
  309.             _connection.RootPath = RootPath;
  310.             _connection.TableKey = TableKey;
  311.             _connection.TableName = TableName;
  312.             _connection.MaxRecordCount = Convert.ToInt32( _maxRecords, CultureInfo.InvariantCulture.NumberFormat );
  313.             if( CustomSql != null )
  314.             {
  315.                 _connection.CacheName = Target;
  316.             }
  317.             else
  318.             {
  319.                 _connection.CacheName = DBName + TableName;
  320.             }
  321.  
  322.             if(CustomSql != null)
  323.             {
  324.                 _connection.SearchQuery = CustomSql;
  325.             } 
  326.         }
  327.  
  328.         private DataView GetDataView()
  329.         {
  330.             string fpQuery = "";
  331.             if( Where != null )
  332.             {
  333.                 fpQuery = DBQuery.CompleteWhereClause(userFieldsControl, Where );            
  334.             }
  335.  
  336.  
  337.             if((CustomSql != null))
  338.             {
  339.                 ArrayList paramList = new ArrayList();
  340.                 _connection.SearchQuery = DBQuery.CompleteCustomSql( CustomSql, userFieldsControl, paramList );              
  341.                 _connection.SetConnectionParameters(paramList);
  342.             }
  343.         if((userFieldsControl != null && userFieldsControl.Submitted) || !Page.IsPostBack)
  344.             {
  345.                 _connection.RefreshCache();
  346.             }
  347.             return _connection.GetDataView( fpQuery, OrderBy );
  348.         }
  349.     
  350.         private void UpdatePager(bool useLastPage)
  351.         {
  352.             if(targetGrid == null)
  353.             {
  354.                 return;
  355.             }
  356.  
  357.             int VirtualItemCount = GetDataView().Count;
  358.         
  359.             int nMaxPage = ( VirtualItemCount - 1 ) / nPageSize;
  360.         
  361.             if( targetGrid.CurrentPageIndex < 0 )
  362.                 {targetGrid.CurrentPageIndex = 0;}
  363.             if( targetGrid.CurrentPageIndex > nMaxPage || useLastPage)
  364.                 {targetGrid.CurrentPageIndex = nMaxPage;}
  365.             
  366.             buttonFirst.Enabled = buttonPrevious.Enabled = ( targetGrid.CurrentPageIndex != 0 );
  367.             buttonLast.Enabled = buttonNext.Enabled = ( targetGrid.CurrentPageIndex != nMaxPage );
  368.         }
  369.     
  370.         protected void CommandChangePage( Object s, CommandEventArgs e )
  371.         {
  372.             bool lastPage = false;
  373.             if( e.CommandName == "First" )
  374.                 {targetGrid.CurrentPageIndex  = 0;}
  375.             else if( e.CommandName == "Prev" )
  376.                 {targetGrid.CurrentPageIndex --;}
  377.             else if( e.CommandName == "Next" )
  378.                 {targetGrid.CurrentPageIndex ++;}
  379.             else if( e.CommandName == "Last" )
  380.                 {lastPage = true;}
  381.             
  382.             UpdatePager(lastPage);
  383.             DataBind();
  384.         }
  385. </SCRIPT>
  386. <asp:Panel ID="pagerPanel" Runat="server" Visible="False">
  387.     <asp:Button id="buttonFirst" Runat="server" Text=" |< " CausesValidation="False" OnCommand="CommandChangePage" CommandName="First"></asp:Button>
  388.     <asp:Button id="buttonPrevious" Runat="server" Text="  < " CausesValidation="False" OnCommand="CommandChangePage" CommandName="Prev"></asp:Button>
  389.     <asp:Button id="buttonNext" Runat="server" Text=" >  " CausesValidation="False" OnCommand="CommandChangePage" CommandName="Next"></asp:Button>
  390.     <asp:Button id="buttonLast" Runat="server" Text=" >| " CausesValidation="False" OnCommand="CommandChangePage" CommandName="Last"></asp:Button>
  391. </asp:Panel>
  392.